const CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {
  lintOnSave: false,
  productionSourceMap: false,
  transpileDependencies: ['element-ui', 'ele-admin', 'vue-i18n'],  // 不需要兼容IE注释这行可提升编译速度
  chainWebpack: (config) => {
    config.plugins.delete('prefetch');
    if (process.env.NODE_ENV !== 'development') {
      // 对超过10kb的文件gzip压缩
      config.plugin('compressionPlugin').use(new CompressionWebpackPlugin({
        test: /\.(js|css|html)$/,
        threshold: 10240
      }));
      // 打包优化开始
      config.optimization.splitChunks({
        chunks: 'all',
        cacheGroups: {
          vendors: {
            name: 'chunk-vendors',
            test: /[\\/]node_modules[\\/]/,
            priority: 10,
            chunks: 'initial'
          },
          elementui: {
            name: 'chunk-elementui',
            priority: 20,  // 优先级，要比vendors高
            test: /[\\/]node_modules[\\/]_?element-ui(.*)/
          },
          echarts: {
            name: 'chunk-echarts',
            priority: 20,
            test: /[\\/]node_modules[\\/]_?(echarts|zrender)(.*)/  // zrender是echarts的依赖，打包在一起
          }
        }
      });
    }
  },
  css: {
    loaderOptions: {
      sass: {
        sassOptions: {
          outputStyle: 'expanded'
        }
      }
    }
  },
  pluginOptions:{
    electronBuilder:{
      nodeIntegration:true,
      builderOptions: {
        "appId": "com.electron.EasyOA",
        "productName": "EasyOA",//项目名，也是生成的安装文件名，即aDemo.exe
        "copyright": "Copyright © 2019",//版权信息
        "asar": true,
        "directories": {
          "buildResources": "public/resources/icons",
          "output": "./build"//输出文件路径
        },
        "win": {
          "icon": "./public/resources/icons/icon.ico",
          "target": [
            {
              "target": "nsis",
              "arch": [
                "x64",
                "ia32"
              ]
            }
          ]
        },
        "nsis": {
          "oneClick": false,
          "perMachine": true,
          "allowToChangeInstallationDirectory": true,
          "displayLanguageSelector": true,
          "language": 2052
        }
      }
    }
  }
}
